#!/bin/bash

nginx=/opt/module/nginx/sbin/nginx
log_home=/opt/gmall0624
jar=logger-0.0.1-SNAPSHOT.jar

case $1 in
"start")
# 启动 nginx
if [[ -z "`pgrep nginx`" ]]; then
    echo "在hadoop162上启动nginx"
    ${nginx}
else
    echo "nginx已经启动, 无序重复启动"
fi

# 分别在三个节点启动日志服务器
for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 启动日志服务器"
    ssh ${host} "nohup java -jar ${log_home}/${jar} 1>$log_home/log.log 2>&1 &"
done

;;

"stop")
echo "在hadoop162上停止nginx"
${nginx} -s stop

# 分别在三个节点启动日志服务器
for host in hadoop162 hadoop163 hadoop164 ; do
    echo "在 $host 停止日志服务器"
    ssh ${host} "jps  | awk '/${jar}/ {print \$1}' | xargs kill -9"
done
;;

*)
    echo "你启动的姿势不对: "
    echo " logger.sh start 启动日志采集: "
    echo " logger.sh stop  停止日志采集: "
;;
esac



